﻿using System;
using System.Configuration;
using System.ComponentModel;

namespace mki.Backup.Objects
{
	/// <summary>
	/// Represents the ConnectionString class
	/// </summary>
	public class BackupJobElement : CustomConfigurationElement
	{
		#region Properties (15)

		// Public Properties (15) 

		/// <summary>
		/// Gets or sets a value indicating whether [attach log file].
		/// </summary>
		/// <value>
		///   <c>true</c> if [attach log file]; otherwise, <c>false</c>.
		/// </value>
		[ConfigurationProperty("attachLogFile", IsRequired = false, DefaultValue = false)]
		[Description("Sets a value indicating whether to attach log file or not"), Category("Behavior")]
		public Boolean AttachLogFile
		{
			get { return Boolean.Parse(this["attachLogFile"].ToString()); }
			set { this["attachLogFile"] = value; }
		}

		/// <summary>
		/// Gets or sets a value indicating whether [continue on error].
		/// </summary>
		/// <value>
		///   <c>true</c> if [continue on error]; otherwise, <c>false</c>.
		/// </value>
		[ConfigurationProperty("continueOnError", IsRequired = false, DefaultValue = true)]
		[Description("Sets a value indicating whether the job should be continued on error or not"), Category("Behavior")]
		public Boolean ContinueOnError
		{
			get { return Boolean.Parse(this["continueOnError"].ToString()); }
			set { this["continueOnError"] = value; }
		}

		/// <summary>
		/// Gets the backup jobs collection.
		/// </summary>
		[ConfigurationProperty("dbBackups", IsDefaultCollection = false)]
		[ConfigurationCollection(typeof(DBBackupSection), AddItemName = "dbBackup", ClearItemsName = "clear", RemoveItemName = "remove")]
		[Browsable(false)]
		public DBBackupSection DBBackupJobsCollection
		{
			get { return base["dbBackups"] as DBBackupSection; }
			set { this["dbBackups"] = value; }
		}

		/// <summary>
		/// Gets or sets a value indicating whether this <see cref="BackupJobElement"/> is enabled.
		/// </summary>
		/// <value><c>true</c> if enabled; otherwise, <c>false</c>.</value>
		[ConfigurationProperty("enabled", IsRequired = false, DefaultValue = true)]
		[Description("Sets a value indicating whether this job is enabled or not"), Category("Behavior")]
		public Boolean Enabled
		{
			get { return Boolean.Parse(this["enabled"].ToString()); }
			set { this["enabled"] = value; }
		}

		/// <summary>
		/// Gets the DB backup jobs collection.
		/// </summary>
		[ConfigurationProperty("ftpJobs", IsDefaultCollection = false)]
		[ConfigurationCollection(typeof(FTPJobSection), AddItemName = "ftpJob", ClearItemsName = "clear", RemoveItemName = "remove")]
		[Browsable(false)]
		public FTPJobSection FTPJobsCollection
		{
			get { return base["ftpJobs"] as FTPJobSection; }
			set { this["ftpJobs"] = value; }
		}

		/// <summary>
		/// Gets or sets the log file path.
		/// </summary>
		/// <value>
		/// The log file path.
		/// </value>
		[Browsable(false)]
		public String LogFilePath { get; set; }

		/// <summary>
		/// Gets or sets the name.
		/// </summary>
		/// <value>The name.</value>
		[ConfigurationProperty("name", IsRequired = true, IsKey = true)]
		[Description("Backup job name"),
			Category("Design")]
		public new String Name
		{
			get { return base["name"].ToString(); }
			set
			{
				base["name"] = value;
				base.OnPropertyChanged("Name");
			}
		}

		/// <summary>
		/// Gets the DB backup jobs collection.
		/// </summary>
		[ConfigurationProperty("runProcesses", IsDefaultCollection = false)]
		[ConfigurationCollection(typeof(RunProcessSection), AddItemName = "runProcess", ClearItemsName = "clear", RemoveItemName = "remove")]
		[Browsable(false)]
		public RunProcessSection RunProcessJobsCollection
		{
			get { return base["runProcesses"] as RunProcessSection; }
			set { this["runProcesses"] = value; }
		}

		/// <summary>
		/// Gets or sets a value indicating whether [E mail notification].
		/// </summary>
		/// <value>
		///   <c>true</c> if [E mail notification]; otherwise, <c>false</c>.
		/// </value>
		[ConfigurationProperty("sendResultMailTo", IsRequired = false)]
		[Description("Sets the job result recipient"), Category("Behavior")]
		public String SendResultMailTo
		{
			get { return this["sendResultMailTo"].ToString(); }
			set { this["sendResultMailTo"] = value; }
		}

		/// <summary>
		/// Gets or sets the start job at.
		/// </summary>
		/// <value>
		/// The start job at.
		/// </value>
		[ConfigurationProperty("startJobAt", IsRequired = true, DefaultValue = "22:00")]
		[Description("Sets the job start time"), Category("Behavior")]
		public String StartJobAt
		{
			get { return this["startJobAt"].ToString(); }
			set { this["startJobAt"] = value; }
		}

		/// <summary>
		/// Gets or sets a value indicating whether this <see cref="BackupJobElement"/> is successfull.
		/// </summary>
		/// <value>
		///   <c>true</c> if successfull; otherwise, <c>false</c>.
		/// </value>
		[Browsable(false)]
		public Boolean Successfull { get; set; }

		/// <summary>
		/// Gets or sets the end time.
		/// </summary>
		/// <value>
		/// The end time.
		/// </value>
		[Browsable(false)]
		public TimeSpan TimeEnd { get; set; }

		/// <summary>
		/// Gets the time for execution.
		/// </summary>
		[Browsable(false)]
		public String TimeForExecution
		{
			get
			{
				return (this.TimeEnd - this.TimeStart).TotalSeconds.ToString();
			}
		}

		/// <summary>
		/// Gets or sets the start time.
		/// </summary>
		/// <value>
		/// The start time.
		/// </value>
		[Browsable(false)]
		public TimeSpan TimeStart { get; set; }

		/// <summary>
		/// Gets the DB backup jobs collection.
		/// </summary>
		[ConfigurationProperty("zipJobs", IsDefaultCollection = false)]
		[ConfigurationCollection(typeof(ZipJobSection), AddItemName = "zipJob", ClearItemsName = "clear", RemoveItemName = "remove")]
		[Browsable(false)]
		public ZipJobSection ZipJobsCollection
		{
			get { return base["zipJobs"] as ZipJobSection; }
			set { this["zipJobs"] = value; }
		}

		#endregion Properties
	}
}